<template>
    <div id="first">
        <img id="img1" src="https://img1.dxycdn.com/2021/0712/393/4508851123457791943-22.png" alt="" />
        <div class="search">
            <el-icon class="icon1">
                <Search />
            </el-icon>
            <input type="text" placeholder="文章/医生/疾病/医院" v-model.lazy="str" />
            <span id="sp1" @:click="go('/search?searched=')">搜索</span>
        </div>

        <div class="down"> 
            <div className="down_left" @:click="go('/ask')">
                <div style="font-size: 28px;">
                    问医生
                </div>
                <div style="font-size: 6px;margin-top: 8px;">
                    三甲主治在线
                </div>
            </div>
            <div className="down_right">
                <div @:mouseenter.self="make(index)" class="down_right_son" v-for="(el,index) in arr" key="index">
                    <div class="drs_div1" @click="fn">
                        <div class="drs_sp1">
                            {{el[0]}}
                        </div>
                        <div class="drs_sp2">
                            {{el[1]}}
                        </div>
                    </div>
                    <div class="drs_div2" :class="{floa:index==num}" :style="{backgroundPosition:(el[2] as string)}">
                        <!-- 图标 -->
                    </div>
                </div>
            </div>
        </div>
    </div>

</template>

<script setup lang="ts">
import { ref, watch } from "vue"
import { useRouter } from "vue-router";

let str: any = ref("")
let router = useRouter()

function fn() {
    router.push("/searcher/disease")
}

let searched = ''
function go(x: string): any {
    router.push(x + searched)
}

async function search(arg: string): Promise<string> {
    // let re: any = await axios("/search", { params: arg })
    // console.log(arg)
    return "str"
}
watch(str, (newdata: string, olddata: string) => {
    searched = newdata
    // console.log(newdata, "searched", searched)
    search(newdata)
})

let arr = [
    ["查疾病", "权威疾病百科", "-200px -51px"],
    ["查药品", "药品信息大全", "-490px -51px"],
    ["查医院", "国内医院信息查询", "-780px -51px"],
    ["查检查/手术", "检查与手术专业百科", "-1070px -51px"],
    ["查疫苗", "疫苗接种与禁忌", "-200px -212px"],
    ["查急救指南", "急救知识百科查询", "-490px -212px"],
    ["查测一测", "1分钟了解自己", "-780px -212px"],
    ["查科普视频", "生活辟谣与科普", "-1070px -212px"],
]

let count: any = ref(0), flag: boolean = true, counted = ref('0px')
// watch(count,(newdata,olddata)=>{
//     count=
// })
let nowtime: any = "", lasttime: any = "", num: any = ref("")
let timer
function make(x: number) {
    num.value = x
    clearInterval(timer)
    // 
    nowtime = new Date()  //本次触发时间
    if (lasttime && (nowtime - lasttime < 500)) {
        clearInterval(timer)
    } else {
        timer = setInterval(() => {
            lasttime = nowtime //记录上次触发时间
            if (flag) {
                if (count.value == 5) {
                    flag = false
                } else {
                    count.value++
                    counted.value = -count.value + 'px'
                }
            } else {
                if (count.value == 0) {
                    clearInterval(timer)
                    flag = true
                } else {
                    counted.value = -count.value + 'px'
                    count.value--
                }
            }
        }, 30)
    }
}

</script>
<style scoped  lang="scss">
#img1 {
    width: 180px;
    margin: 100px 0 0 -90px;
    position: relative;
    left: 50%;
}

.search {
    width: 721px;
    margin: 30px auto;
    position: relative;
    display: flex;
    justify-content: flex-start;

    input {
        width: 510px;
        height: 46px;
        font-size: 16px;
        margin: 0;
        padding: 0;
        padding-left: 46PX;
        border: 0;
        background-color: #CCE8CF;


        &:focus {
            outline: none;
        }
    }

    #sp1 {
        padding: 0;
        width: 138px;
        height: 46px;
        display: inline-block;
        text-align: center;
        color: white;
        line-height: 44px;
        border-color: transparent;
        background-color: #00c792;

        &:hover {
            opacity: 0.7;
        }

    }

}

.icon1 {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 30px;
    font-weight: 700;
    color: #F2FAFA;
}

.down {
    margin-top: 80px;
    background-size: 100%;
    display: flex;
    justify-content: flex-start;

    margin-bottom: 60px;

    .down_left {
        width: 186px;
        height: 180px;
        border-radius: 5px;
        padding: 36px 20px;
        background-color: white;
        background-image: url("https://img1.dxycdn.com/2020/0821/847/0477797599034961343-22.png");
        background-size: 220px 258px;
    }

    .down_right {
        width: 982px;
        height: 264;
        // 226 120 12

        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;

        .down_right_son {
            width: 186px;
            height: 48px;
            padding: 36px 20px;
            margin-left: 12px;
            margin-bottom: 12px;
            border-radius: 5px;
            background-color: white;
            display: flex;
            justify-content: space-between;

            .drs_div2 {
                width: 44px;
                height: 44px;
                // border: 1px black solid;
                background-image: url("./picture/2.jpg");
                background-size: 2600%;
            }

            .drs_sp1 {
                font-size: 20px;
            }

            .drs_sp2 {
                margin-top: 8px;
                font-size: 13px;
            }
        }
    }
}

.floa {
    position: relative;
    top: v-bind(counted);
}

// .sp2 {
//     width: 100px;
//     height: 44px;
//     line-height: 44px;
//     border-color: transparent;
//     background-color: white;
// }
</style>